package com.sxt.test;

import java.util.Set;

import org.hibernate.Session;
import org.junit.Test;

import com.sxt.entity.Student;
import com.sxt.entity.Teacher;
import com.sxt.factory.HibernateSessionFactory;

public class ManyToMany {
	/**
	 * 查询
	 */
	@Test
	public void test1() {
		Session session = HibernateSessionFactory.getSession();
		Teacher teacher = (Teacher) session.get(Teacher.class, 1);
		Set<Student> students = teacher.getStudents();
		for (Student student : students) {
			System.out.println(student.getName());
		}
		session.close();
	}
	
	@Test
	public void test2() {
		Session session = HibernateSessionFactory.getSession();
		Student student = (Student) session.get(Student.class, 1);
		Set<Teacher> teachers = student.getTeachers();
		for (Teacher teacher : teachers) {
			System.out.println(teacher.getName());
		}
		session.close();
	}
}
